// 行为页面功能
if (window.location.pathname === '/action') {
    const form = document.querySelector('form');
    form.addEventListener('submit', (event) => {
        const commandInput = document.querySelector('input[name="command"]');
        if (!commandInput.value.trim()) {
            alert('请输入指令！');
            event.preventDefault(); // 阻止表单提交
        } else {
            const confirmation = confirm(`确认执行指令: "${commandInput.value}" 吗？`);
            if (!confirmation) {
                event.preventDefault(); // 阻止表单提交
            }
        }
    });
}

// 查询页面功能
if (window.location.pathname === '/query') {
    const form = document.querySelector('form');
    form.addEventListener('submit', (event) => {
        const sensorIdInput = document.querySelector('input[name="sensor_id"]');
        if (!sensorIdInput.value.trim()) {
            alert('请输入传感器编号！');
            event.preventDefault(); // 阻止表单提交
        }
    });
}


// 主页面动态效果
if (window.location.pathname === '/main') {
    const sidebarLinks = document.querySelectorAll('.sidebar ul li a');
    sidebarLinks.forEach((link) => {
        link.addEventListener('click', (event) => {
            sidebarLinks.forEach((l) => l.classList.remove('active'));
            event.target.classList.add('active');
        });
    });
}

// 登出按钮点击事件
if (window.location.pathname === '/main') {
    const logoutLink = document.querySelector('.logout');
    logoutLink.addEventListener('click', (event) => {
        const confirmation = confirm("确定要退出登录吗？");
        if (!confirmation) {
            event.preventDefault(); // 阻止默认行为
        }
    });
}

